/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package net.javlov.vf;

import net.javlov.State;

public class BasicStateTrace implements StateTrace {

	protected double gamma, lambda, addVal, currVal;
	
	protected Value stateValue;
	
	protected boolean accumulating;
	
	public BasicStateTrace(double gamma, double lambda) {
		this(gamma, lambda, 1, false);
	}
	
	public BasicStateTrace(double gamma, double lambda, double addVal, boolean accumulating) {
		this.gamma = gamma;
		this.lambda = lambda;
		this.addVal = addVal;
		this.accumulating = accumulating;
		currVal = 0;
	}
	
	@Override
	public void firstVisit(State s, Value val) {
		stateValue = val;
		currVal = addVal;
	}

	@Override
	public Value getValue() {
		return stateValue;
	}

	@Override
	public StateTrace newInstance() {
		return new BasicStateTrace(gamma, lambda, addVal, accumulating);
	}

	@Override
	public void update(State s) {
		currVal *= gamma*lambda;
	}
	
	public double getTrace() {
		return currVal;
	}

	public void visit() {
		if ( accumulating )
			currVal += addVal;
		else
			currVal = addVal;
	}
	
	

}
